package com.nineclock.system.controller;

import com.nineclock.api.system.SysCompanyUserControllerApi;
import com.nineclock.common.entity.Result;
import com.nineclock.system.dto.SysCompanyUserDTO;
import com.nineclock.system.service.SysCompanyUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/companyUser")
public class SysCompanyUserController implements SysCompanyUserControllerApi {

    @Autowired
    private SysCompanyUserService companyUserService;

    @Override
    @GetMapping("/query")
    public Result<List<SysCompanyUserDTO>> queryCompanyUser(@RequestParam(value = "userId", required = false) Long userId,
                                                            @RequestParam(value = "companyId", required = false)Long companyId) {
        List<SysCompanyUserDTO> companyUserDTOS = companyUserService.queryCompanyUser(userId, companyId);
        return Result.success(companyUserDTOS);
    }


    @Override
    @GetMapping("/query/{companyUserId}")
    public Result<SysCompanyUserDTO> queryByCompanyUserId(@PathVariable("companyUserId") Long companyUserId) {
        SysCompanyUserDTO companyUserDTO = companyUserService.queryByCompanyUserId(companyUserId);
        return Result.success(companyUserDTO);
    }


    @Override
    @GetMapping("/queryAllUser")
    public Result<List<SysCompanyUserDTO>> queryAllCompanyUser() {
        List<SysCompanyUserDTO> companyUsers = companyUserService.queryAllCompanyUser();
        return Result.success(companyUsers);
    }


    @Override
    @GetMapping("/queryone")
    public Result<SysCompanyUserDTO> findCompanyUserByMobile(String mobile) {
        SysCompanyUserDTO companyUserDTO = companyUserService.findCompanyUserByMobile(mobile);
        return Result.success(companyUserDTO);
    }


    @Override
    @GetMapping("/queryAdminByCompanyId")
    public Result<SysCompanyUserDTO> queryAdminByCompanyId(@RequestParam(value = "companyId") Long companyId) {
        SysCompanyUserDTO companyUserDTO = companyUserService.queryAdminByCompanyId(companyId);
        return Result.success(companyUserDTO);
    }
}
